1
|
|
|
/* global API */ |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nextcloud - passman |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
7
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
(function () { |
26
|
|
|
'use strict'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @ngdoc function |
30
|
|
|
* @name passmanApp.controller:MainCtrl |
31
|
|
|
* @description |
32
|
|
|
* # MainCtrl |
33
|
|
|
* Controller of the passmanApp |
34
|
|
|
*/ |
35
|
|
|
angular.module('passmanExtension') |
36
|
|
|
.controller('MainCtrl', ['$scope', 'Settings', '$location', '$rootScope', '$timeout', function ($scope, Settings, $window, $rootScope, $timeout) { |
37
|
|
|
|
38
|
|
|
var port = API.runtime.connect(null, { |
39
|
|
|
name: "PassmanCommunication" |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
var messageParser = function (message) { |
44
|
|
|
var e = message.split(':'); |
45
|
|
|
|
46
|
|
|
switch (e[0]) { |
|
|
|
|
47
|
|
|
case "credential_amount": |
48
|
|
|
$scope.credential_amount = e[1]; |
49
|
|
|
$scope.refreshing_credentials = false; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$scope.$apply(); |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Connect to the background service |
57
|
|
|
*/ |
58
|
|
|
var initApp = function () { |
59
|
|
|
port.onMessage.addListener(messageParser); |
60
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "getMasterPasswordSet"}).then(function (isPasswordSet) { |
61
|
|
|
//First check attributes |
62
|
|
|
if (!isPasswordSet) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
$scope.refreshing_credentials = true; |
66
|
|
|
setTimeout(function () { |
67
|
|
|
port.postMessage("credential_amount"); |
68
|
|
|
}, 500); |
69
|
|
|
}); |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$scope.refreshing_credentials = false; |
74
|
|
|
$scope.refresh = function () { |
75
|
|
|
$scope.refreshing_credentials = true; |
76
|
|
|
API.runtime.sendMessage(API.runtime.id, {method: "getCredentials"}).then(function () { |
77
|
|
|
setTimeout(function () { |
78
|
|
|
port.postMessage("credential_amount"); |
79
|
|
|
}, 1900); |
80
|
|
|
}); |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
$scope.menuIsOpen = false; |
84
|
|
|
$scope.bodyOverflow = false; |
85
|
|
|
$scope.showHeader = true; |
86
|
|
|
|
87
|
|
|
$scope.toggleMenu = function () { |
88
|
|
|
$scope.menuIsOpen = !$scope.menuIsOpen; |
89
|
|
|
$scope.bodyOverflow = true; |
90
|
|
|
$timeout(function () { |
91
|
|
|
$scope.bodyOverflow = false; |
92
|
|
|
}, 1500); |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
$rootScope.$on('hideHeader', function () { |
96
|
|
|
$scope.showHeader = false; |
97
|
|
|
}); |
98
|
|
|
|
99
|
|
|
$rootScope.$on('showHeader', function () { |
100
|
|
|
$scope.showHeader = true; |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
104
|
|
|
|
105
|
|
|
$rootScope.app_settings = settings; |
106
|
|
|
if (!settings || Object.keys(settings).length === 0) { |
107
|
|
|
window.location = '#!/setup'; |
108
|
|
|
} else if (settings.hasOwnProperty('isInstalled')) { |
109
|
|
|
window.location = '#!/locked'; |
110
|
|
|
} else { |
111
|
|
|
initApp(); |
112
|
|
|
} |
113
|
|
|
}); |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
$scope.goto = function (page) { |
117
|
|
|
window.location = '#!/' + page; |
118
|
|
|
$scope.menuIsOpen = false; |
119
|
|
|
}; |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
$scope.lockExtension = function () { |
123
|
|
|
API.runtime.sendMessage(API.runtime.id, { |
124
|
|
|
method: "setMasterPassword", |
125
|
|
|
args: {password: null} |
126
|
|
|
}).then(function () { |
127
|
|
|
window.location = '#!/locked'; |
128
|
|
|
}); |
129
|
|
|
}; |
130
|
|
|
}]); |
131
|
|
|
}()); |
132
|
|
|
|
133
|
|
|
|